PRG 1.0 TXT

/*
	Color Correction for Post Process
*/

//-----------------------------------------------------------------------------
// [CONFIG]

include "..\program_include.ocf"

object Program
{
	ubo_data	= array /*UBO*/ {
		{ "inParams",	e_program_data.POSTPROCESS_PARAMS }
	}

	textures	= array /*ProgramTexture*/ {
		{ "unColorMap", e_texture.DIFFUSE }
	}
	
	uniforms	= array /*string*/ {
		"transform", "unTransform."
	}
}


//-----------------------------------------------------------------------------
// [VERTEX]

#version 330 core
#pragma optimize(on)

#define ATTR_POSITION	0
#define ATTR_TEXCOORD	2
#define ATTR_COLOR		1

layout(location = ATTR_POSITION)	in vec3 inPosition;
layout(location = ATTR_TEXCOORD)	in vec2 inTexcoord;


uniform struct Transform {
	mat4	Projection;
} unTransform;


out	TVertexData {
	vec2	vTexcoord;
} Output;


void main()
{
	gl_Position  	 = unTransform.Projection * vec4(inPosition, 1.0);
	Output.vTexcoord = inTexcoord;
}


//-----------------------------------------------------------------------------
// [FRAGMENT]

#version 330 core
#pragma optimize(on)

layout(location = 0, index = 0) out vec4	outColor;

uniform sampler2D	unColorMap;


layout (std140)
uniform inParams {
	vec4	aColors[18];
	float	fMix;
	float	fBrightness;
} unPalate;


in	TVertexData {
	vec2	vTexcoord;
} Input;


vec3 Filter(in vec3 color)
{
	const vec3	factor	= vec3( 0.27, 0.67, 0.06 );
	const float param	= 18.0;

	float		a   	= dot( factor, color ) * param;
	int			idx 	= int( clamp( a, 0.0, 16.0 ) );
	
	a -= float(idx);
	
	return vec3( mix( unPalate.aColors[idx], unPalate.aColors[idx+1], a ) );
}


vec3 ColorFilter(in vec3 color)
{
	return ( ( Filter(color) - color ) * unPalate.fMix + color ) * unPalate.fBrightness;
}


void main()
{
	vec4	color = texture( unColorMap, Input.vTexcoord );
	outColor = vec4( ColorFilter( color.rgb ), color.a );
}

// [END]
